(display "\n========================================\n")
(define (make-interval a b) (cons a b))
(define (lower-bound z) (car z))
(define (upper-bound z) (cdr z))

(define (add-interval x y)
    (make-interval (+ (lower-bound x) (lower-bound y))
                   (+ (upper-bound x) (upper-bound y))))

(define (mul-interval x y)
    (let ((p1 (* (lower-bound x) (lower-bound y)))
          (p2 (* (lower-bound x) (upper-bound y)))
          (p3 (* (upper-bound x) (lower-bound y)))
          (p4 (* (upper-bound x) (upper-bound y))))
         (make-interval (min p1 p2 p3 p4)
                        (max p1 p2 p3 p4))))

(define (div-interval x y)
    (mul-interval x
                  (make-interval (/ 1 (lower-bound y))
                                 (/ 1 (upper-bound y)))))

(define (par1 r1 r2)
    (div-interval (mul-interval r1 r2)
                  (add-interval r1 r2)))

(define (par2 r1 r2)
    (let ((one (make-interval 1 1)))
        (div-interval one
                      (add-interval (div-interval one r1)
                                    (div-interval one r2)))))

(define r1 (make-interval 100.0 101))
(define r2 (make-interval 200.0 202))

(display (par1 r1 r2))
(newline)
(display (par2 r1 r2))
(newline)
; 确实不一样！

(define (make-center-percent c p)
    (make-interval (- c (* c p)) (+ c (* c p))))

(define (center i)
    (/ (+ (lower-bound i) (upper-bound i)) 2))
(define (percent i)
    (/ (- (upper-bound i) (lower-bound i)) 2))

(define A (make-center-percent 100 0.01))
(define B (make-center-percent 200 0.00001))

(define AA (div-interval A A))
(define BB (div-interval B B))

(display AA)    ; 不是 1！
(newline)
(display (center AA))
(newline)
(display (percent AA))
(newline)
(display (par1 A A))
(newline)
(display (par2 A A))
(newline)

(display BB)
(newline)
(display (center BB))
(newline)
(display (percent BB))
(newline)
(display (par1 B B))
(newline)
(display (par2 B B))

(display "\n========================================\n")
